package cn.edu.sspu.www.controller.common;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.edu.sspu.www.domain.SysUser;
import cn.edu.sspu.www.service.SysUserService;

/**
 * 校验控制器
 * @author warm
 * @version 2019年07月11日
 */
@Controller
@RequestMapping("/unauth")
public class CheckController {
	
	@Autowired
	private SysUserService service;

	/**
	 * 校验
	 * @param loginName or nickName
	 * @return
	 */
	@RequestMapping("/checkName")
	@ResponseBody
	public Object checkName(SysUser queryVo) {
		List<SysUser> infos = service.querySysUserList(queryVo);
		if(null == infos || infos.size() == 0) {
			return true;
		};
		return false;
	}
	

	/**
	 * 校验
	 * @param loginName or nickName
	 * @return
	 */
	@RequestMapping("/checkNickName")
	@ResponseBody
	public Object checkNickName(SysUser queryVo) {
		Long id = queryVo.getId();
		queryVo.setId(null);
		List<SysUser> infos = service.querySysUserList(queryVo);
		if(null == infos || infos.size() == 0) {
			return true;
		} else if(infos.size() == 1) {
			if (id.intValue() == infos.get(0).getId().intValue()) {
				return true;
			}
		}
		return false;
	}
}
